	define(['app','cart'],function(app,cart){

	app.controller("myCtl",['$scope','$http','$rootScope',"cart",function($scope,$http,$rootScope,cart){
	
		$http.get("http://localhost:8888/hot1").then(function(data){
			$scope.datas=data.data.Data.sata;
		});
		$http.get("http://localhost:8888/classify-class").then(function(data){
			$scope.clsaaify0=data.data.Data.Items;
			$scope.classdata0=[]
			angular.forEach($scope.clsaaify0, function(value, key){
				angular.forEach(value.SecChannel, function(value1, key1){
					$scope.classdata0.push(value1)
				});
			});
			$scope.classdata=$scope.classdata0;		
		});
		$http.get("http://localhost:8888/classify-doc").then(function(data){
			$scope.clsaaify1=data.data.Data.Items;
			$scope.classdata1=[];
			angular.forEach($scope.clsaaify1, function(value, key){
				angular.forEach(value.SecChannel, function(data, key1){
					$scope.classdata1.push(data);
				});
			});
		});
		$http.get("http://localhost:8888/classify-sex").then(function(data){
			$scope.clsaaify2=data.data.Data.Items;
			$scope.classdata2=[];
			angular.forEach($scope.clsaaify2, function(value, key){
				angular.forEach(value.SecChannel, function(data, key1){
					$scope.classdata2.push(data);
				});
			});
			return $scope.classdata2;
		});
		$http.get("http://localhost:8888/ganmaofashao").then(function(data){
			$scope.ganmaofashao=data.data.Data;
		});
		$http.get("http://localhost:8888/like").then(function(data){
			$scope.like=data.data.Data;
		});
		$http.get("http://localhost:8888/seckill").then(function(data){
			$scope.seckill=data.data.SeckillWares;
			$scope.seckill.splice(3);
		});
		$http.get("http://localhost:8888/buyCar").then(function(data){
			$scope.buyCar=data.data.Data;
		});

		$http.get("http://localhost:8888/home_seckill").then(function(data){
			$scope.home_seckill0 = data.data.SeckillWares;
			$scope.home_seckill = $scope.home_seckill0;
		});
		$http.get("http://localhost:8888/home_seckill-2").then(function(data){
			$scope.home_seckill1 = data.data.data;
		});
		$scope.classify_nav = [
			{"name":"推荐分类"},
			{"name":"中西药品"},
			{"name":"成人分类"},
			{"name":"家庭药箱"},
			{"name":"健康体检"},
			{"name":"医疗器械"},
			{"name":"营养保养"},
			{"name":"中药饮品"},
			{"name":"隐形眼镜"},
			{"name":"家庭电器"}
		]
		$scope.num = 0;
		$scope.classnav = function(index){
			$scope.num = index;
			$scope.classdata = $scope["classdata"+$scope.num];
		}
		$scope.seckillClick = function(num){
			$scope.home_seckill = $scope["home_seckill"+num]
		}
		//高亮
		$scope.highlight = function(index){
			$scope.highlightnum = index;
		}
		//数据传递
		$scope.chuan = null;
		$scope.chuandi = function(data){
			$scope.chuan=data
		}
		//购物车部分
		//////////////////
		//添加购物车
		$scope.addcart = function(shop){
			cart.addProduct(shop)
			console.log("+1")
				
		}
		//购物车减
		$scope.removecart = function(shop){
			cart.removeProduct(shop.WareSkuCode)
			console.log("-1")
		}
		
		//商品数量
		$scope.counts = function(id){
			return cart.getCount(id)
		}
		
		//获取购物车数据
		$scope.shopdata = cart.getProduct();
		
	    //移除商品
	    $scope.yichu =  function(index){
	    	$scope.shopdata.splice(index,1)
	    }
		//清空购物车
		$scope.qingkong = function(){
			$scope.shopdata.length=0
		}
	  //商品结算数组
		$scope.buydata = cart.getProduct().slice(0)
		
		//选中结算变色
		$scope.buycolor = function(data){
			return $scope.buydata.indexOf(data)==-1?"":"yellow";
		}
		//结算
		$scope.total = function(){
			var total = 0;
			for(var i = 0;i <$scope.buydata.length;i++){
					total+=($scope.buydata[i].SalePrice*$scope.buydata[i].count)
			}
			total = parseInt(total*10)/10
			return total;
		}
		//结算按钮变色
		$scope.buycolortotal = function(){
			return $scope.buydata.length > 0?"yellow":"";
		}
		
	
		//全选按钮变色
		$scope.quanxuan = function(){
			return $scope.buydata.length==$scope.shopdata.length?"yellow":"";
		}
		//是否添加结算
		$scope.buy = function(data){
			if($scope.buydata.indexOf(data)==-1){
				$scope.buydata.push(data)
			}else{
				$scope.buydata.splice($scope.buydata.indexOf(data),1)
			}
		}
			//全选按钮
		$scope.quanxuanbuy = function(){
			if($scope.buydata.length==$scope.shopdata.length){
				$scope.buydata=[]
			}else{
				$scope.buydata=$scope.shopdata.slice(0)
			}
		}
		//价格求整
		$scope.qiuzheng = function(shop){
			return parseInt(shop.SalePrice*shop.count*10)/10
		}
		
		//点赞吐槽切换
	$scope.dz=[];
		$scope.btndz = function(){
			$scope.dz.length=0;
			document.getElementById("dz").style.background="blue";
			document.getElementById("dz").style.color="#fff"
			document.getElementById("tc").style.background="#fff";
			document.getElementById("tc").style.color="blue";
		}
		$scope.btntc = function(){
			$scope.dz.length=1
			document.getElementById("dz").style.background="#fff";
			document.getElementById("tc").style.background="blue";
			document.getElementById("tc").style.color="#fff";
			document.getElementById("dz").style.color="blue";
			/*$scope.dz.length=1?"tcs":""*/
		}
		
	}])
})